home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 039a / cppcom.zip / TIMER.H < prev    next >
C/C++ Source or Header  |  1991-04-14  |  2KB  |  83 lines

  1. #ifndef TIMER_H
  2. #define TIMER_H
  3.  
  4. // Copyright ***********************************************************
  5. //
  6. //     The information in this file is copyright 1991 by David Orme.
  7. //
  8. //        Anyone may use this information for any purpose as long as he takes
  9. //        responsability for any and all libility incurred from its use
  10. //        or misuse and acknowledges its use in the user documentation.  This
  11. //        information is provided AS IS with no warrenty of any kind, either
  12. //        expressed or implied.
  13. //
  14. // End *****************************************************************
  15.  
  16.  
  17. // Contents **********************************************************
  18. //
  19. //        Timer class definition
  20. //
  21. // Description
  22. //
  23. //        The timer class implements a simple DOS timer ISR and allows
  24. //        timing tasks to be accomplished while other processing
  25. //        occurs.  Note that all instances of this class reference the
  26. //        _same_ timer ISR in memory.
  27. //
  28. // End ***************************************************************
  29.  
  30.  
  31. // Interface dependencies ---------------------------------------------
  32.  
  33. // -- NONE --
  34.  
  35.  
  36. // Implementation dependencies ----------------------------------------
  37.  
  38. // -- NONE --
  39.  
  40.  
  41.  
  42. // Global variables ---------------------------------------------------
  43.  
  44. const int TIMER = 0x1c;        // DOS timer int vector
  45.  
  46.  
  47. class Timer {
  48. private:
  49.     static volatile unsigned long ticker;
  50.     static void interrupt (far *oldtimer)(...);
  51.     static void interrupt far NewTimer(...);
  52.  
  53. public:
  54.     Timer();
  55.     ~Timer();
  56.     void Set(float seconds=0)    { ticker=seconds*182/10+1; }
  57.     int TimeOut()                    { return !ticker; }
  58. };
  59.  
  60. // Description ---------------------------------------------------------
  61. //
  62. //        Defines the Timer class;  The constructor sets up NewTimer
  63. //        as an ISR on the DOS timer interrupt and sets the ticker
  64. //        to 0.  The timer may be set to time any task in the background
  65. //        while other processing occurs and requires a minimal amount
  66. //        of CPU time.
  67. //
  68. // SetTimer(unsigned seconds=0)
  69. //
  70. //        Set the timer to return to 0 in as many secs as you like.
  71. //
  72. // int TimeOut()
  73. //
  74. //        Returns true (!0) when the time set by SetTimer has elapsed.
  75. //
  76. // End -----------------------------------------------------------------
  77.  
  78.  
  79.  
  80.  
  81. #endif
  82.  
  83.